import 'package:flutter/material.dart';
import 'package:pdftron_flutter/pdftron_flutter.dart';
import 'package:open_file/open_file.dart';

class FileViewPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => _FileViewPageState();
}

class _FileViewPageState extends State {
    String _version = 'Unknown';

  @override
  void initState() {
    super.initState();
    // initPlatformState();
    // PdftronFlutter.openDocument("https://pdftron.s3.amazonaws.com/downloads/pdfref.pdf");
    OpenFile.open("https://pdftron.s3.amazonaws.com/downloads/pdfref.pdf");
  }

  // Platform messages are asynchronous, so we initialize via an async method.
  Future<void> initPlatformState() async {
    String version;
    try {
      PdftronFlutter.initialize("abc");
      version = await PdftronFlutter.version;
    } on Error {
    }

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() {
      _version = version;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('PDFTron flutter app'),
        ),
        body: Center(
          child: Text('Running on:\n'),
        ),
      ),
    );
  }
}
